﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Royaumes_Libres.Database;

namespace Royaumes_Libres
{
    public partial class usercombat : System.Web.UI.Page
    {
        public int PkKingdomDef;
        public cKingdom KingdomDef;
        public cUsers User;
        public cKingdom KingdomAtk;
        public cArmy ArmyAtk;

        protected void Page_Load(object sender, EventArgs e)
        {
            User = (cUsers)Session[Properties.Settings.Default.ObjUser];
            KingdomAtk = new cKingdom(User.PkUser, User.ActiveWorld);
            ArmyAtk = new cArmy(KingdomAtk.PkKingdom);

            if (Cache["PkKingdomDef"] != null)
            {
                PkKingdomDef = Convert.ToInt32(Cache["PkKingdomDef"]);
                KingdomDef = new cKingdom(PkKingdomDef);
                if (!IsPostBack)
                {
                    Fill();
                }
            }
            else
            {
                this.divCombat.InnerHtml = "<h1>Selectionnez une ville à attaquer sur la map...</h1>";
            }
        }

        protected void Fill()
        {
            this.lblKingdomName.Text = KingdomDef.ToString();
            this.lblTimeTravel.Text = cAttack.GetTimeTravel(KingdomAtk.PkKingdom, KingdomDef.PkKingdom).ToString();
            this.lblNbWarrior.Text = ArmyAtk.NbWarrior.ToString();
            this.lblNbArcher.Text = ArmyAtk.NbArcher.ToString();
            this.lblNbKnight.Text = ArmyAtk.NbKnight.ToString();
            this.lblNbPriest.Text = ArmyAtk.NbPriest.ToString();
        }

        protected void btnAttack_Click(object sender, EventArgs e)
        {
            int NbWarrior = Convert.ToInt32(this.txtNbWarrior.Text);
            int NbArcher = Convert.ToInt32(this.txtNbArcher.Text);
            int NbKnight = Convert.ToInt32(this.txtNbKnight.Text);
            int NbPriest = Convert.ToInt32(this.txtNbPriest.Text);

            cAttack.Attack(KingdomAtk.PkKingdom, NbWarrior, NbArcher, NbKnight, NbPriest, KingdomDef.PkKingdom);
        }


    }
}